########################################################################
# bannder.py - Defines BannerSizer widget to split a texture and display 
#	a full-justified branding banner
#
# Created 2006.09.12 by Rick Barrett
#
# Copyright (c) 2006 by Pixel Corps.  This program may be used under
# the terms of the X11 license, a copy of which should have accompanied
# this program, in the LICENSE file.
########################################################################

import wx


#### class BannerSizer ################################################

class BannerSizer(wx.FlexGridSizer):
	""" 
	Class defining the BannerSizer
	""" 
	def __init__(self, mainpanel, bannerSrc, width, splitCol):
		wx.FlexGridSizer.__init__(self, 1, 3, vgap = 0, hgap = 0)
		
		wx.InitAllImageHandlers()
		self.fullBanner = wx.Bitmap(bannerSrc, wx.BITMAP_TYPE_GIF)
		
		if splitCol < 1 or splitCol > self.fullBanner.GetWidth():
			print "BANNER: split column invalid - set to image center"
			splitCol = self.fullBanner.GetWidth() / 2
		
		self.leftBanner = self.fullBanner.GetSubBitmap(wx.Rect(0, 0, 
			splitCol, self.fullBanner.GetHeight()));
		
		self.rightBanner = self.fullBanner.GetSubBitmap(wx.Rect(splitCol, 0, 
			self.fullBanner.GetWidth() - splitCol, 
			self.fullBanner.GetHeight()));
		
		self.splitColumn = self.fullBanner.GetSubBitmap(wx.Rect(splitCol, 0, 
			1, self.fullBanner.GetHeight()));
		if width > self.fullBanner.GetWidth():
			self.splitImage = self.splitColumn.ConvertToImage()
			self.splitImage.Rescale(width - self.fullBanner.GetWidth(),
				self.fullBanner.GetHeight())
			self.splitBanner = wx.BitmapFromImage(self.splitImage, -1)
		else:
			self.splitBanner = self.splitColumn
		
		self.leftBitmap = wx.StaticBitmap(mainpanel, wx.ID_ANY, 
			self.leftBanner, (0, 0), 
			(self.leftBanner.GetWidth(), self.leftBanner.GetHeight()))
		self.Add(self.leftBitmap,
			flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
		
		self.splitBitmap = wx.StaticBitmap(mainpanel, wx.ID_ANY, 
			self.splitBanner, (0, 0), 
			(self.splitBanner.GetWidth(), self.splitBanner.GetHeight()))
		self.Add(self.splitBitmap,
			flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
		
		self.rightBitmap = wx.StaticBitmap(mainpanel, wx.ID_ANY, 
			self.rightBanner, (0, 0), 
			(self.rightBanner.GetWidth(), self.rightBanner.GetHeight()))
		self.Add(self.rightBitmap,
			flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
